#include "SingleLinkedList.h"

// 单向链表测试
// 测试添加
void test1() {
    Node* list = init_list();
    add_head(list, 10);
    for (int i = 0; i < 10; ++i) {
        add_tail(list, i);
    }
    add_pos(list, 100, 5);
    // 当pos大于链表长度时，直接在链表尾部添加新节点
    add_pos(list, 200, 20);
    print_list(list);
    clear_list(list);
}

// 测试删除
void test2() {
    Node* list = init_list();
    for (int i = 0; i < 10; ++i) {
        add_tail(list, i);
    }
    del_head(list);
    del_tail(list);
    del_pos(list, 5);
    del_pos(list, 10);
    print_list(list);
}
// 测试查找
void test3() {
    Node* list = init_list();
    for (int i = 0; i < 10; ++i) {
        add_tail(list, i);
    }
    print_list(list);
    printf("get_val: %d\n", get_val(list, 5));
    printf("get_val: %d\n", get_val(list, 10));
    printf("get_val: %d\n", get_val(list, 1));
    printf("get_val: %d\n", get_val(list, 11));
    printf("get_val: %d\n", get_val(list, -1));
    printf("get_head: %d\n", get_head(list));
    printf("get_tail: %d\n", get_tail(list));
    printf("get_len: %d\n", get_len(list));
}

int main() {
    void (*func[])() = {test1, test2, test3};
    int len = sizeof(func) / sizeof(*func);
    for (int i = 0; i < len; ++i) {
        func[i]();
    }
    return 0;
}